package action.dropdown;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;

import model.dropdown.DIndustrycatA;
import model.dropdown.DIndustrycatB;
import service.dropdown.DropDownService;
import core.action.BaseAction;
public class DropDownAction extends BaseAction{
	//get
	private DropDownService dropDownService;
	private List<?> ddlist;
	private String dda_id;
	
	private List<?>dclist;
	
	private int ty;

	public int getTy() {
		return ty;
	}

	public void setTy(int ty) {
		this.ty = ty;
	}

	public List<?> getDclist() {
		return dclist;
	}

	public void setDclist(List<?> dclist) {
		this.dclist = dclist;
	}

	public List<?> getDdlist() {
		return ddlist;
	}

	public void setDdlist(List<?> ddlist) {
		this.ddlist = ddlist;
	}

	public String getDda_id() {
		return dda_id;
	}

	public DropDownService getDropDownService() {
		return dropDownService;
	}

	public void setDropDownService(DropDownService dropDownService) {
		this.dropDownService = dropDownService;
	}

	public void setDda_id(String dda_id) {
		this.dda_id = dda_id;
	}

	public String findIcAList() throws IOException{
		ddlist = dropDownService.getDIndustrycatAList();
		ToJson(ddlist);
		return null;
	}
	
	public String findIcBList() throws IOException{
		ddlist = dropDownService.getDIndustrycatBList(Integer.parseInt(dda_id));
		ToJson(ddlist);
		return null;
	}
	
	
	public String findComList() throws IOException{
		dclist = dropDownService.getCommonList(ty, 0);
		ToJson(dclist);
		return null;
	}
	
	public String ToJson(List<?> ddlist)  throws IOException{
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = null;
		out = response.getWriter();
		String infor = new Gson().toJson(ddlist);
		out.print(infor);	
		try {
			out.flush();
			out.close();
		} catch (Exception e) {
			
		}
		return null;
	}
}
